﻿Imports System.Data.SqlClient

Public Class SQLProvider

    Shared m_strConnection As String = "Server=FAMILY-PC;Database=SapXepTBK;Trusted_Connection=True;"
    Shared m_connection As SqlConnection

    Public Shared Sub Open()
        If m_connection Is Nothing Then
            m_connection = New SqlConnection(m_strConnection)
        End If
        m_connection.Open()

    End Sub

    Public Shared Sub Close()
        m_connection.Close()
    End Sub

    Public Shared Sub ExecNoneQuery(ByVal strSQL As String)
        ' Mo ket noi
        Open()
        ' Thuc thi cau truy van
        Dim command As SqlCommand
        command = New SqlCommand(strSQL, m_connection)
        command.ExecuteNonQuery()

        ' Dong ket noi
        Close()
    End Sub

    Public Shared Function ExecQuery(ByVal strSQL As String) As DataTable
        ' Mo ket noi
        Open()
        ' Thuc thi cau truy van
        Dim adapter As SqlDataAdapter
        adapter = New SqlDataAdapter(strSQL, m_connection)
        Dim dt As New DataTable
        adapter.Fill(dt)
        ' Doc du lieu
        Close()
        Return dt
        ' Dong ket noi
    End Function
End Class

